package cn.miui.mall.service.impl;

import cn.miui.mall.dao.cartdao;
import cn.miui.mall.pojo.shopping_cart;
import cn.miui.mall.service.Cartdaoservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class Cartdaoserviceimpl implements Cartdaoservice {
    @Autowired
    private cn.miui.mall.dao.cartdao cartdao;

    @Override
    public List<shopping_cart> findByuserid(Integer userid) {
        return cartdao.findByuserid(userid);
    }

    @Override
    public boolean addCart(shopping_cart shoppingCart) {
        shopping_cart is=cartdao.findByUseridAndName(shoppingCart.getUserid(),shoppingCart.getName());
        if (is==null){
            cartdao.save(shoppingCart);
        }else{
            int sum=is.getTotal()+1;
            is.setTotal(sum);
            cartdao.save(is);
        }
        return true;
    }
}
